package offer;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class offer_0048 {
    public int lengthOfLongestSubstring(String s) {
        Set<Character> set=new HashSet<>();
        int len=s.length();
        if(len==0) return 0;
        int max=1;
        int left=0;
        int right=0;
        while(right<len){
            char a=s.charAt(right);
            if(!set.contains(a)){
                set.add(a);
                max=Math.max(max,right-left+1);
                right++;
            }
            else {
                while(set.contains(a)){
                    set.remove(s.charAt(left));
                    left++;
                }
                set.add(a);
                right++;
            }
        }
        return max;
    }
}
